package com.fanvil.videoconference;

import android.util.Log;


public class FvlLogger {
    public static final String TAG = FvlLogger.class.getSimpleName();

    public static boolean ON = true;
    public static boolean OFF = false;

    public static final int UNKNOWN = -1;

    public static final int DEFAULT = 0;

    public static final int TRACE = 1;

    /**
     * Priority constant for the println method; use Log.v.
     */
    public static final int VERBOSE = 2;

    /**
     * Priority constant for the println method; use Log.d.
     */
    public static final int DEBUG = 3;

    /**
     * Priority constant for the println method; use Log.i.
     */
    public static final int INFO = 4;

    /**
     * Priority constant for the println method; use Log.w.
     */
    public static final int WARN = 5;

    /**
     * Priority constant for the println method; use Log.e.
     */
    public static final int ERROR = 6;

    /**
     * Priority constant for the println method.
     */
    public static final int ASSERT = 7;

    /*
     * Off
     */
    public static final int SILENT = 8;

    private static int globalLevel = DEBUG;

    private int mLevel;
    private String mTag;
    private boolean mOn = ON;

    FvlLogger(String tag, int level) {
        this.mTag = tag;
        this.mLevel = level;
        if (this.mLevel == SILENT) {
            this.mOn = OFF;
        } else {
            this.mOn = ON;
        }
    }

    public void d(String msg) {
        log(mTag, DEBUG, msg);
    }

    public void i(String msg) {
        log(mTag, INFO, msg);
    }

    public void w(String msg) {
        log(mTag, WARN, msg);
    }

    public void w(String msg, Throwable e) {
        log(mTag, WARN, msg, e);
    }

    public void e(String msg) {
        log(mTag, ERROR, msg);
    }

    public void e(String msg, Throwable e) {
        log(mTag, ERROR, msg, e);
        // e.printStackTrace();
    }

    public void a(String msg) {
        log(mTag, ASSERT, msg);
    }

    public void a(String msg, Throwable e) {
        log(mTag, ASSERT, msg, e);
        // e.printStackTrace();
    }

    public void v(String msg) {
        log(mTag, VERBOSE, msg);
    }

    public void t(String msg) {
        log(mTag, TRACE, msg);
    }

    public boolean isLoggable() {
        return this.mOn == ON && globalLevel != SILENT;
    }

    public static boolean isLogException() {
        return true;
    }

    public static synchronized FvlLogger getLogger(String tag, int level) {
        return new FvlLogger(tag, level);
    }

    private synchronized void log(String tag, int level, String msg) {
        //tag = "[FVL][" + tag + "]";

        if (level < globalLevel || (level == TRACE && globalLevel != TRACE && this.mLevel != TRACE)) {
            return;
        }

        //msg = "["+ level + ":" + globalLevel + "]" + msg;
        if (level == DEBUG) {
            Log.d(tag, msg);
        } else if (level == INFO) {
            Log.i(tag, msg);
        } else if (level == WARN) {
            Log.w(tag, msg);
        } else if (level == ERROR) {
            Log.e(tag, msg);
        } else if (level == ASSERT) {
            Log.e(tag, msg);
        } else {
            Log.v(tag, msg);
        }
    }

    private synchronized void log(String tag, int level, String msg, Throwable e) {
        if (level == ERROR) {
            Log.e(tag, msg, e);
        } else if (level == ASSERT) {
            Log.e(tag, msg, e);
        }
    }
}
